package com.whnk.web.controller.pm;

import java.text.ParseException;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.BaseInfo;
import com.whnk.pm.domain.EduInfo;
import com.whnk.pm.dto.CheckDateDurationDTO;
import com.whnk.pm.service.IBaseInfoService;
import com.whnk.pm.service.IEduInfoService;

/**
 * 教育经历 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-06-13
 */
@Controller
@RequestMapping("/pm/eduInfo")
public class EduInfoController extends BaseController
{
    private String prefix = "pm/eduInfo";
	
	@Autowired
	private IEduInfoService eduInfoService;
	
	@Autowired
	private IBaseInfoService baseInfoService;
	
	@RequiresPermissions("pm:eduInfo:view")
	@GetMapping()
	public String eduInfo()
	{
	    return prefix + "/eduInfo";
	}
	
	/**
	 * 查询教育经历列表
	 */
	@RequiresPermissions("pm:eduInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(EduInfo eduInfo)
	{
		startPage();
        List<EduInfo> list = eduInfoService.selectEduInfoList(eduInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增教育经历
	 */
	@GetMapping("/add/{empId}")
	public String add(@PathVariable("empId") String empId, ModelMap mmap) {
		BaseInfo baseInfo = baseInfoService.selectBaseInfoById(empId);
		mmap.put("baseInfo", baseInfo);
		return prefix + "/add";
	}
	
	/**
	 * 新增保存教育经历
	 */
	@RequiresPermissions("pm:eduInfo:add")
	@Log(title = "教育经历", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(EduInfo eduInfo)
	{		
		return toAjax(eduInfoService.insertEduInfo(eduInfo));
	}

	/**
	 * 修改教育经历
	 */
	@GetMapping("/edit/{empSn}")
	public String edit(@PathVariable("empSn") Integer empSn, ModelMap mmap)
	{
		EduInfo eduInfo = eduInfoService.selectEduInfoById(empSn);
		mmap.put("eduInfo", eduInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存教育经历
	 */
	@RequiresPermissions("pm:eduInfo:edit")
	@Log(title = "教育经历", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(EduInfo eduInfo)
	{		
		return toAjax(eduInfoService.updateEduInfo(eduInfo));
	}
	
	/**
	 * 删除教育经历
	 */
	@RequiresPermissions("pm:eduInfo:remove")
	@Log(title = "教育经历", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(eduInfoService.deleteEduInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param empSn
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:eduInfo:detail")
	@GetMapping("/detail/{empSn}")
	public String detail(@PathVariable("empSn") Integer empSn, ModelMap mmap) {
		EduInfo eduInfo = eduInfoService.selectEduInfoById(empSn);
		mmap.put("eduInfo", eduInfo);
		return prefix + "/detail";
	} 

	/**
	 * 
	 * @param checkDateDurationDTO
	 * @return
	 * @throws ParseException
	 */
	@PostMapping("/checkDate")
	@ResponseBody
	public String checkDuration(CheckDateDurationDTO checkDateDurationDTO) throws ParseException {
		return eduInfoService.checkDate(checkDateDurationDTO.getStartDate(), checkDateDurationDTO.getEndDate(),
				checkDateDurationDTO.getEmpId(), checkDateDurationDTO.getOperationType(), checkDateDurationDTO.getId());
	}
}
